package com.teach.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.teach.entity.user;
import com.teach.service.UserService;
import com.teach.service.impl.UserServiceImpl;

public class UserFindServlet extends HttpServlet{
	private UserService userService = new UserServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		Integer userId=null;
		try{
			userId = Integer.valueOf(req.getParameter("userId"));
			 
		}catch(Exception ex){
			throw new ServletException("参数错误", ex);
		}
		
		try{
			user u = userService.select(userId);
			req.setAttribute("user", u);
		}catch(Exception ex){
			ex.printStackTrace();//记调试日志
			req.setAttribute("error", "获取用户失败:"+ex.getMessage());
		}
		
		req.getRequestDispatcher("/admin/user-find.jsp").forward(req, resp);
		
	}
}
